//
//  MainMenu.m
//  CountDown2
//
//  Created by mmac on 11/19/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "MainMenuView.h"
#import "PlayViewController.h"

@implementation MainMenuView

@synthesize viewController;


- (UIButton *)buttonWithFrame:(CGRect)frame normalImage:(UIImage *)normalImage highlightedImage:(UIImage *)highlightedImage disabledImage:(UIImage *)disabledImage target:(id)target selector:(SEL)inSelector {
    UIButton *button = [[UIButton alloc] initWithFrame:frame];
    button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    
    // Image for normal state
    UIImage *newNormalImage = [normalImage stretchableImageWithLeftCapWidth:10 topCapHeight:10];
    [button setBackgroundImage:newNormalImage forState:UIControlStateNormal];
    
    // Image for highlighted state
    UIImage *newHighlightedImage = [highlightedImage stretchableImageWithLeftCapWidth:10 topCapHeight:10];
    [button setBackgroundImage:newHighlightedImage forState:UIControlStateHighlighted];
    
    // Image for disabled state
    UIImage *newDisabledImage = [disabledImage stretchableImageWithLeftCapWidth:10 topCapHeight:10];
    [button setBackgroundImage:newDisabledImage forState:UIControlStateDisabled];
    
    [button addTarget:target action:inSelector forControlEvents:UIControlEventTouchUpInside];
    button.adjustsImageWhenDisabled = YES;
    button.adjustsImageWhenHighlighted = YES;
    [button setBackgroundColor:[UIColor clearColor]];    // in case the parent view draws with a custom color or gradient, use a transparent color
    [button autorelease];
    return button;
}

- (id)initWithFrame:(CGRect)frame viewController:(PlayViewController *)aController {
    self = [super initWithFrame:frame];
    if (self != nil) {
        self.viewController = aController;
		
        [self setupSubviewsWithContentFrame:frame];
    }
    return self;
}

-(void)setupSubviewsWithContentFrame:(CGRect)frameRect{
	NSLog(@"Cover View contentFrame at (%u,%u) %ux%u", frameRect.origin.x, frameRect.origin.y, frameRect.size.width, frameRect.size.height);
	
	[self setOpaque:YES];
	
	CGRect buttonFrame = CGRectZero;
	UIImage *imageNormal = nil;
    UIImage *imageHighlighted = nil; 
    UIImage *imageDisabled = nil;
	
	// set up start button
    float startButtonShiftRight = 330.0;
    float startButtonShiftDown = 226.0;
    
    imageNormal = [UIImage imageNamed:@"start_button.png"];
    imageHighlighted = [UIImage imageNamed:@"start_button_highlight.png"];
    imageDisabled = nil;
    buttonFrame = CGRectMake(startButtonShiftRight, startButtonShiftDown, imageNormal.size.width, imageNormal.size.height);
    startButton = [self buttonWithFrame:buttonFrame normalImage:imageNormal highlightedImage:imageHighlighted disabledImage:imageDisabled target:self selector:@selector(startAction:)];
    startButton.enabled = YES;
    [self addSubview:startButton];
    
	
	// set up about button
    float aboutButtonShiftRight = 330.0;
    float aboutButtonShiftDown = 276.0;
	
    imageNormal = [UIImage imageNamed:@"about_button.png"];
    imageHighlighted = [UIImage imageNamed:@"about_button_highlight.png"];
    imageDisabled = nil;
    buttonFrame = CGRectMake(aboutButtonShiftRight, aboutButtonShiftDown, imageNormal.size.width, imageNormal.size.height);
    aboutButton = [self buttonWithFrame:buttonFrame normalImage:imageNormal highlightedImage:imageHighlighted disabledImage:imageDisabled target:self selector:@selector(aboutAction:)];
    aboutButton.enabled = YES;
    [self addSubview:aboutButton];
	
	
}


- (void)startAction:(id)sender {
	NSLog(@"startAction");
    [self.viewController loadLevel];
}

- (void)aboutAction:(id)sender {
	NSLog(@"aboutAction");
    [self.viewController loadAbout];
}


- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Initialization code
    }
    return self;
}




- (void)drawRect:(CGRect)rect {
    // Drawing code
	
	
}


- (void)dealloc {
    [super dealloc];
}


@end
